package com.syys.privacy.controller;

import com.syys.common.annotation.Log;
import com.syys.common.core.controller.BaseController;
import com.syys.common.core.domain.AjaxResult;
import com.syys.common.core.page.TableDataInfo;
import com.syys.common.enums.BusinessType;
import com.syys.common.utils.poi.ExcelUtil;
import com.syys.privacy.domain.QaPrivacy;
import com.syys.privacy.service.IQaPrivacyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 隐私政策Controller
 *
 * @author ys
 * @date 2021-07-13
 */
@Controller
@RequestMapping("/privacy")
public class PrivacyHomeController extends BaseController {
    private String prefix = "privacy/privacy";

    @Autowired
    private IQaPrivacyService qaPrivacyService;

    @GetMapping()
    public String privacy() {
        return prefix + "/privacy";
    }

    @GetMapping("qa")
    public String privacyQa() {
        return prefix;
    }

    /**
     * 查询隐私政策列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QaPrivacy qaPrivacy) {
        startPage();
        List<QaPrivacy> list = qaPrivacyService.selectQaPrivacyList(qaPrivacy);
        return getDataTable(list);
    }

    /**
     * 导出隐私政策列表
     */
    @Log(title = "隐私政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QaPrivacy qaPrivacy) {
        List<QaPrivacy> list = qaPrivacyService.selectQaPrivacyList(qaPrivacy);
        ExcelUtil<QaPrivacy> util = new ExcelUtil<QaPrivacy>(QaPrivacy.class);
        return util.exportExcel(list, "隐私政策数据");
    }

    /**
     * 新增隐私政策
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存隐私政策
     */
    @Log(title = "隐私政策", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QaPrivacy qaPrivacy) {
        return AjaxResult.success(qaPrivacyService.saveQaPrivacy(qaPrivacy));
    }

    /**
     * 修改隐私政策
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        QaPrivacy qaPrivacy = qaPrivacyService.selectQaPrivacyById(id);
        mmap.put("qaPrivacy", qaPrivacy);
        return prefix + "/edit";
    }

    /**
     * 修改保存隐私政策
     */
    @Log(title = "隐私政策", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QaPrivacy qaPrivacy) {
        return toAjax(qaPrivacyService.updateQaPrivacy(qaPrivacy));
    }

    /**
     * 删除隐私政策
     */
    @Log(title = "隐私政策", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(qaPrivacyService.deleteQaPrivacyByIds(ids));
    }
}
